﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ServiceNetworkDesign.Utilities
{
    public class Path
    {
        private double totalWeight;
        private List<string> passedIDArray; //站点  排好序的
        private List<Edge> passedEdge;//路径
        private List<Node> listNodes;//所有节点
        public Path(List<Node> listNode,List<string> path,double weight)
        {
            if (path == null) return;
            passedIDArray = path;
            passedEdge = new List<Edge>();
            totalWeight = weight;
            listNodes = listNode;
        }
        public double TotalWeight
        {
            get { return totalWeight; }
        }
        public List<string> PassedIDArray
        {
            get { return passedIDArray; }
        }
        public List<Edge> PassedEdge
        {
            get
            {
                if ((passedIDArray == null)||(passedIDArray.Count()<1)) return null;
                for(int i=0;i<passedIDArray.Count()-1;i++)
                {
                    Node curNode = listNodes.Find(p => p.ID == passedIDArray[i]);
                    Edge curEdge = curNode.EdgeList.Find(p => p.EndNodeID == passedIDArray[i + 1]);
                    if (!passedEdge.Contains(curEdge))
                    {
                        passedEdge.Add(curEdge);
                    }
                }
                if (passedEdge.Count() < 1) return null;
                return passedEdge;
            }
               
        }
    }
}
